#include<stdio.h>
#include"object.h"
#include<allegro.h>

void deplacement_balancoire(Bal * b)
{

BITMAP *back;
BITMAP *buffer;
BITMAP *ima;
int i;

b->x=350;
b->y=300;

b->images_right[0]=load_bitmap("/home/niss/etude/final/objet/bal/bal0.bmp",NULL);
b->images_right[1]=load_bitmap("/home/niss/etude/final/objet/bal/bal1.bmp", NULL);
b->images_right[2]=load_bitmap("/home/niss/etude/final/objet/bal/bal2.bmp",NULL);
b->images_right[3]=load_bitmap("/home/niss/etude/final/objet/bal/bal3.bmp",NULL);
b->images_right[4]=load_bitmap("/home/niss/etude/final/objet/bal/bal4.bmp",NULL);


b->images_left[0]=load_bitmap("/home/niss/etude/final/objet/bal/bal0.bmp",NULL);
b->images_left[1]=load_bitmap("/home/niss/etude/final/objet/bal/bal-1.bmp",NULL);
b->images_left[2]=load_bitmap("/home/niss/etude/final/objet/bal/bal-2.bmp",NULL);
b->images_left[3]=load_bitmap("/home/niss/etude/final/objet/bal/bal-3.bmp",NULL);

back = load_bitmap("/home/niss/etude/final/objet/bal/bac.bmp", NULL);
buffer = create_bitmap(back->w,back->h);
ima = load_bitmap("/home/niss/etude/final/objet/bal/bal0.bmp",NULL);


if ( (ima==NULL) && (back == NULL)) 
{
allegro_message("could not load images");
allegro_exit();
}

blit(back, buffer, 0, 0, 0, 0,back->w, back->h);
draw_sprite(buffer, ima, 140, 180);
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);


//if(install_timer() < 0)
//allegro_message(" EREEUR ");

while(!key[KEY_ESC])
{

     for(i=0;i<4;i++)
      {
       usleep(100000);
       blit(back,buffer,0,0,0,0,back->w,back->h);
       draw_sprite(buffer, b->images_right[i], 140, 180);
       blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
      }
   
    for(i=4;i>0;i--)
        {
       usleep(100000);
       blit(back,buffer,0,0,0,0,back->w,back->h);
       draw_sprite(buffer, b->images_right[i], 140, 180);
       blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
          }
 
for(i=0;i<4;i++)
      {
       usleep(100000);
       blit(back,buffer,0,0,0,0,back->w,back->h);
       draw_sprite(buffer, b->images_left[i], 140, 180);
       blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
      }
   
    for(i=3;i>0;i--)
        {
       usleep(100000);
       blit(back,buffer,0,0,0,0,back->w,back->h);
       draw_sprite(buffer, b->images_left[i], 140, 180);
       blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
          }

}
readkey();
destroy_bitmap(ima);
destroy_bitmap(buffer);
}

void deplacement_moulin(Bal *m)
{
   BITMAP *back;
   BITMAP *buffer;
   BITMAP *ima;
   int i;

m->images_right[0]=load_bitmap("/home/niss/etude/final/objet/moulin/moulin.bmp",NULL);
m->images_right[1]=load_bitmap("/home/niss/etude/final/objet/moulin/moulin1.bmp",NULL);
m->images_right[2]=load_bitmap("/home/niss/etude/final/objet/moulin/moulin2.bmp",NULL);
m->images_right[3]=load_bitmap("/home/niss/etude/final/objet/moulin/moulin3.bmp",NULL);
m->images_right[4]=load_bitmap("/home/niss/etude/final/objet/moulin/moulin4.bmp",NULL);
m->images_right[5]=load_bitmap("/home/niss/etude/final/objet/moulin/moulin5.bmp",NULL);
m->images_right[6]=load_bitmap("/home/niss/etude/final/objet/moulin/moulin6.bmp",NULL);

back = load_bitmap("/home/niss/etude/final/objet/moulin/bac.bmp", NULL);
buffer = create_bitmap(back->w,back->h);
ima = load_bitmap("/home/niss/etude/final/objet/moulin/moulin.bmp",NULL);

if ( (ima==NULL) && (back == NULL)) 
{
allegro_message("could not load images");
allegro_exit();
}

blit(back, buffer, 0, 0, 0, 0,back->w, back->h);
draw_sprite(buffer, ima, 140, 190);
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

while(!key[KEY_ESC])
{

     for(i=0;i<6;i++)
      {
       usleep(100000);
       blit(back,buffer,0,0,0,0,back->w,back->h);
       draw_sprite(buffer, m->images_right[i], 140, 190);
       blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
      }    
}

readkey();
destroy_bitmap(ima);
destroy_bitmap(buffer);
}

void deplacement_voiture(Bal *v,Bal * v1)
{

BITMAP *back;
   BITMAP *buffer;
   BITMAP *ima;
   int i;

v->images_right[0]=load_bitmap("/home/niss/etude/final/objet/car/car1/ghbjn.bmp",NULL);
v->images_right[1]=load_bitmap("/home/niss/etude/final/objet/car/car1/2.bmp",NULL);

back = load_bitmap("/home/niss/etude/final/objet/moulin/bac.bmp", NULL);
buffer = create_bitmap(back->w,back->h);
ima = load_bitmap("/home/niss/etude/final/objet/car/car1/ghbjn.bmp",NULL);

if ( (ima==NULL) && (back == NULL)) 
{
allegro_message("could not load images");
allegro_exit();
}

blit(back, buffer, 0, 0, 0, 0,back->w, back->h);
draw_sprite(buffer, ima, 190, 600);
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

